/*
-----------------------------------------------------------------------------
Filename:    TutorialApplication.h
-----------------------------------------------------------------------------

This source file is part of the
   ___                 __    __ _ _    _ 
  /___\__ _ _ __ ___  / / /\ \ (_) | _(_)
 //  // _` | '__/ _ \ \ \/  \/ / | |/ / |
/ \_// (_| | | |  __/  \  /\  /| |   <| |
\___/ \__, |_|  \___|   \/  \/ |_|_|\_\_|
      |___/                              
      Tutorial Framework
      http://www.ogre3d.org/tikiwiki/
-----------------------------------------------------------------------------
*/
#ifndef __TutorialApplication_h_
#define __TutorialApplication_h_

#include "BaseApplication.h"
#include <QString>
#include <QObject>
#include <QList>
#include "entity.h"
#include "onode.h"
#include "oplane.h"
#include "light.h"
#include "ocamera.h"
#include <QElapsedTimer>

enum Command {
    STOP = 0, PAUSE, RESUME
};

class OgreApplication :public QObject, public BaseApplication
{
    Q_OBJECT
public:
    OgreApplication(void);
    virtual ~OgreApplication(void);

    void setObjectQueue(QList<BasicObject*>* q) {
        objectQueue = q;
    }

    void setNodeQueue(QList<ONode*>* q) {
        nodeQueue = q;
    }

    void setCmdQueue(QList<Command>* q) {
        cmdQueue = q;
    }

    void setMainCamera(Ogre::Camera * camera);

signals:
    void frameRendered(int timeElapsed);
    void ready(Ogre::SceneManager* m_manager);
    void stopped();
    void keyPress(int key);

protected:
    virtual void createScene(void);
    void renderOneFrame();
    bool keepRunning();
    bool prepare();
    void processObjQueue();
    void processCmdQueue();

    bool keyPressed( const OIS::KeyEvent &arg );

    // object creation

    Ogre::SceneNode* createNode(ONode* node);
    Ogre::Entity* createEntity(OEntity* entity);
    Ogre::Plane* createPlane(OPlane* plane);
    Ogre::Light* createLight(OLight* light);
    Ogre::Camera* createCamera(OCamera* Camera);

    bool m_keepRunning;
    bool m_paused;

    QList<BasicObject * > * objectQueue;
    QList<ONode * > * nodeQueue;
    QList<Command>* cmdQueue;
    QElapsedTimer time;

public slots:
    void run();

};

#endif // #ifndef __TutorialApplication_h_
